'use strict';
const db = uniCloud.database()
const food = db.collection('food_data')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let data;
	let pageSize = event.pageSize || 10
	let currentPage = event.currentPage || 1
	if (event.status == 1) {
		data = await food.where({
			status: event.status
		}).skip(pageSize * (currentPage - 1)).limit(pageSize).get()
	} else {
		data = await food.where({
			openid: event.openid,
			status: event.status
		}).skip(pageSize * (currentPage - 1)).limit(pageSize).get()
	}
	//返回数据给客户端
	return {
		code: 200,
		data
	}
};